// 04myCenter/01myWallet/02enterpriseChange/enterpriseChange.js
var co = require('../../../resource/js/common.js')
var app = getApp()
var _this, _data, _opt,_bizInfo

Page({

   /* 页面的初始数据*/
   data: {
      change: '',
      userInfo:'',//用户信息
      bizInfo:'',//企业信息
      bizID:'',//企业ID
   },

   /*生命周期函数--监听页面加载*/
   onLoad: function(options) {
      _this = this
      _data = this.data
      _opt = options
      console.log('options',_opt)
      this.setData({
         bizID:_opt.biz_ID
      })
      //this.get_new_balance(_opt.biz_ID)
      this.getBizDetail()      
   },

   onShow: function() {      
      _this.setData({
         change:''
      })
      _this.get_new_balance(_data.bizID)
      //console.log('bizInfo',app.Data.bizInfo)
   },
   //获取新的账户余额
   get_new_balance: function(bizID) {
      co.getJyhsApi('money/Recordbiz/getBalance', {
         Biz_ID: bizID
      }, function(res) {         
         //app.Data.bizInfo.Biz_Money = res.data.Biz_Balance
         //console.log('app.Data === a', app.Data)
         _this.setData({
            change: res.data.Biz_Balance
         })
      });
   },
   //获取商家信息
   getBizDetail: function() {
      var url = 'jyhs/Admin/getInfo'
      co.getShareApi(url, {
         Biz_ID: _opt.biz_ID
      }, function(res) {
         if (res.code == 0) { 
            _this.setData({
               bizInfo:res.data
            })           
            // app.Data.bizInfo = res.data
            wx.setStorageSync('bizInfo', res.data)
            _this.get_new_balance() //获取商家余额
         }
      })
   },
   // 跳转到我的银行卡页面
   bankCard: function() {
      wx.navigateTo({
         url: "/04myCenter/01myWallet/02enterpriseChange/enterprisebankCard/enterprisebankCard",
      })
   },

   //未做功能
   //前往充值和提现页面
   recharge: function(e) {
      if (app.Data.userInfo.PayPassword_Is_Set == 0) {
         co.confirm('未设置支付密码', '取消', '前往设置', function (res) {
            if (res) {
               wx.navigateTo({
                  url: "/04myCenter/02bindPhone/bindPhone",
               })
            }
         })
         return
      }
      var id = e.currentTarget.dataset.id
      var url_end = id == 1 ? 'Recharge/enterpriseRecharge' : 'Widthdraw/enterpriseWidthdraw'
      console.log('url_end===', url_end)
      
      wx.navigateTo({
         url: '/04myCenter/01myWallet/02enterpriseChange/enterprise' + url_end,
      })
   },
})